package com.vanzo.some.interphone;

import android.os.Parcel;
import android.os.Parcelable;

import com.orm.SugarRecord;
import com.orm.dsl.Table;

import java.util.Comparator;

/**
 * Created by tisen on 2017/12/27.
 */
@Table
public class Connect extends SugarRecord implements Comparator<Connect>, Parcelable {
    private int rank;
    private String title;
    private double tx;
    private double rx;
    private int color_code;
    private int owner_id;
    private int group_id;

    public Connect() {
    }

    public Connect(int rank, String title, double tx, double rx, int color_code, int owner_id, int group_id) {
        this.rank = rank;
        this.title = title;
        this.tx = tx;
        this.rx = rx;
        this.color_code = color_code;
        this.owner_id = owner_id;
        this.group_id = group_id;
    }

    protected Connect(Parcel in) {
        rank = in.readInt();
        title = in.readString();
        tx = in.readDouble();
        rx = in.readDouble();
        color_code = in.readInt();
        owner_id = in.readInt();
        group_id = in.readInt();
    }

    public static final Creator<Connect> CREATOR = new Creator<Connect>() {
        @Override
        public Connect createFromParcel(Parcel in) {
            return new Connect(in);
        }

        @Override
        public Connect[] newArray(int size) {
            return new Connect[size];
        }
    };

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public double getTx() {
        return tx;
    }

    public void setTx(double tx) {
        this.tx = tx;
    }

    public double getRx() {
        return rx;
    }

    public void setRx(double rx) {
        this.rx = rx;
    }

    public int getColor_code() {
        return color_code;
    }

    public void setColor_code(int color_code) {
        this.color_code = color_code;
    }

    public int getOwner_id() {
        return owner_id;
    }

    public void setOwner_id(int owner_id) {
        this.owner_id = owner_id;
    }

    public int getGroup_id() {
        return group_id;
    }

    public void setGroup_id(int group_id) {
        this.group_id = group_id;
    }

    @Override
    public int compare(Connect o1, Connect o2) {
        return o1.getRank() - o2.getRank();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Connect connect = (Connect) o;

        return rank == connect.rank;

    }

    @Override
    public int hashCode() {
        return rank;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(rank);
        dest.writeString(title);
        dest.writeDouble(tx);
        dest.writeDouble(rx);
        dest.writeInt(color_code);
        dest.writeInt(owner_id);
        dest.writeInt(group_id);
    }
}
